package top.hundreds.oasys.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import top.hundreds.common.crud.bean.PageParam;
import top.hundreds.common.crud.service.BaseService;
import top.hundreds.oasys.bean.converter.Converter;
import top.hundreds.oasys.bean.entity.Personnel;
import top.hundreds.oasys.bean.enums.CommonStatus;
import top.hundreds.oasys.bean.vo.PersonnelVo;
import top.hundreds.oasys.mapper.PersonnelMapper;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * (Personnel)表服务实现类
 *
 * @author lcf
 * @since 2021-01-29 19:18:50
 */
@Service("personnelService")
public class PersonnelService extends BaseService<Personnel, PersonnelMapper> {

    @Resource
    private Converter<Personnel,PersonnelVo> personnelVoBuilder;

    public PersonnelVo buildVo(Personnel personnel) {
        PersonnelVo personnelVo = new PersonnelVo();
        personnelVoBuilder.buildVo(personnel,personnelVo);
        personnelVo.setStatusName(CommonStatus.formValue(personnelVo.getStatus()).getLabel());
        return personnelVo;
    }

    public List<PersonnelVo> list(PageParam<Personnel> pageParam) {
        Page<Personnel> page = getPage(pageParam);
        List<Personnel> records = page.getRecords();
        List<PersonnelVo> list = new ArrayList<>(records.size());
        for (Personnel record : records) {
            list.add(buildVo(record));
        }
        return list;
    }

    public void setStatus(Long id, Integer status) {
        this.mapper.setStatus(id,status);
    }
}
